﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.ScheduleJob.SPI;

namespace T.FAS.Runtime.ScheduleJob.Service
{
    public class TriggerCommonUtil
    {
        public static bool IsEffectiveTimeLimit(Metadata.Entity.ScheduleJob.ScheduleJob sJob)
        {
            if (sJob != null && sJob.ScheduleTrigger != null)
            {
                var targetEffectiveTime = sJob.ScheduleTrigger.EffectiveTime;
                if (targetEffectiveTime <= DateTime.Now)
                    return false;
                return true;
            }
            return false;
        }
        public static bool IsExpiredTimeLimit(Metadata.Entity.ScheduleJob.ScheduleJob sJob)
        {
            if (sJob != null && sJob.ScheduleTrigger != null)
            {
                var targetExpiredTime = sJob.ScheduleTrigger.ExpiredTime;
                if (targetExpiredTime <= DateTime.Now)
                    return false;
                return true;
            }
            return false;
        }

        public static void ConstructBuilder(TriggerBuilder builder, Metadata.Entity.ScheduleJob.ScheduleJob sJob)
        {
            //指定了过期时间
            if (!sJob.ScheduleTrigger.ExpiredTime.Equals(T.FAS.Runtime.Metadata.Entity.ScheduleJob.ScheduleJobConst.SysDefaultExpiredTime))
            {
                builder = builder.EndAt(sJob.ScheduleTrigger.ExpiredTime);
            }
        }
    }
}
